package com.graduation.mathematics.presenter;

import com.graduation.mathematics.bean.UserInfo;
import com.graduation.mathematics.config.Session;
import com.graduation.mathematics.constract.LoginContract;

import org.litepal.LitePal;

import java.util.List;

/**
 * Created by apc_allen
 * date : 2/17/21
 * description :
 */
public class LoginPresenter implements LoginContract.Presenter {

    protected LoginContract.View mView;

    public LoginPresenter(LoginContract.View view) {
        mView = view;
    }


    @Override
    public void login(String name, String pwd) {
        List<UserInfo> userInfoList = LitePal.where("account = ? and password = ?", name, pwd).find(UserInfo.class);
        if (userInfoList.size() > 0) {
            if (userInfoList.get(0) != null) {
                mView.onLoginSuccess(userInfoList.get(0));
                Session.setScUserInfo(userInfoList.get(0));
            }
        } else {
            mView.onLoginFailed("用户名或密码错误！");
        }
    }
}
